var $newplaces 	= $('#newplacecontainer'),
	serverUrl	= 'http://localhost/zigo/server/home.php/';
	
NewPlace = Backbone.Model.extend({
	urlRoot: serverUrl + 'newplace'
});

NewPlaceCollection = Backbone.Collection.extend({
	model: NewPlace,
	url: serverUrl + 'newplace'
});

NewPlaceViewItem = Backbone.View.extend({
	tagName: 'li',
	className: 'one_third',
	initialize: function() {
		this.render = _.bind(this.render, this);
		this.template = _.template($('#newplace-item').html());
		//this.model.bind('change', this.render);
	},
	render: function() {
		this.$el.html(this.template(this.model.attributes));
		return this;
	}
});
NewPlaceList = Backbone.View.extend({
	initialize: function() {
		_(this).bindAll('add');

		this._newplaces = [];
		
		this.collection.each(this.add);
		
		this.collection.bind('add', this.add);
	},
	render: function() {
		this._rendered = true;
		this.$el.empty();
		_(this._newplaces).each(function(item) {
			$newplaces.append(item.render().el);
		});
	},
	add: function(place) {
		var newPlaceItem = new NewPlaceViewItem({model: place});

		this._newplaces.push(newPlaceItem);

		if (this._rendered) {
			this.$el.append(newPlaceItem.render().el);
		}
	}
});